package leetcode_双指针;

/**
 * 287.寻找重复数
 * 算法：双指针
 *
 * @author yezh
 * @date 2023/12/29 18:27
 */
public class _287 {

    public int findDuplicate(int[] nums) {
        int slow = nums[0], fast = nums[nums[0]];
        while (slow != fast) {
            slow = nums[slow];
            fast = nums[nums[fast]];
        }
        int p1 = 0, p2 = slow;
        while (p1 != p2) {
            p1 = nums[p1];
            p2 = nums[p2];
        }
        return p1;
    }

}
